<?php

namespace api\modules\v1\controllers;

use Yii;
use yii\helpers\ArrayHelper;
use filsh\yii2\oauth2server\filters\ErrorToExceptionFilter;
use api\controllers\BaseController;

class Oauth2Controller extends BaseController
{
    public $modelClass = '';
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'exceptionFilter' => [
                'class' => ErrorToExceptionFilter::className()
            ],
            'authenticator' => [
                'except' => ['token'],
            ],
        ]);
    }
    
    public function actionToken()
    {
        $module = Yii::$app->getModule('oauth2');
        $response = $module->getServer()->handleTokenRequest();
        return $response->getParameters();
    }
}